Hashing Graphs Trees Search Trees Indexing and Multiway Trees File Organization

Introduction

Graph ADT

Data Structure of Graph

Implementation of Graph

Graph traversals

Directed Graph

Planarity

Shortest path Dijkstra’s algorithm

Shortest paths Floyd's algorithm

Minimal Spanning Trees

Travelling salesman and Vehicle Routing

Graphs are a fundamental concept in computer science and real-world applications, representing connections between entities. Let's imagine a social network, where each person is a vertex, and friendships are edges connecting them. Now, how do we represent this network in a computer? There are several ways, but let's explore three popular methods: the edge list structure, the adjacency list structure, and the adjacency matrix.


1. Edge List Structure:


Imagine you have a list of people and a separate list of friendships. For example, you might have:

List of People: Alice, Bob, Charlie, Dave
List of Friendships: (Alice, Bob), (Bob, Charlie), (Charlie, Dave)


In this representation, each person is stored as a vertex object, and each friendship is stored as an edge object. This is like having a list of connections without any additional structure. It's simple to understand but not the most efficient.

Advantages:


a. Easy to understand.
b. Direct access from edges to vertices.


Disadvantage:


Inefficient for operations like finding all edges incident upon a vertex.




2. Adjacency List Structure:


Now, let's enhance our representation. Instead of just storing edges, we also store for each vertex a list of its adjacent vertices. For example:

Alice: [Bob]
Bob: [Alice, Charlie]
Charlie: [Bob, Dave]
Dave: [Charlie]


In this representation, each vertex maintains a list of its neighbors. This allows us to quickly find adjacent vertices and incident edges.


Advantages


Faster access to incident edges and adjacent vertices.
More memory-efficient for sparse graphs (graphs with few edges).


Disadvantages


Still requires searching through lists to find all edges incident upon a vertex.




3. Adjacency Matrix Structure:


Imagine a grid where rows and columns represent vertices, and each cell indicates whether there's an edge between the corresponding vertices. For example:


Alice Bob Charlie Dave Alice 0 1 0 0 Bob 1 0 1 0 Charlie 0 1 0 1 Dave 0 0 1 0

Here, a 1 indicates there's an edge between vertices, and a 0 indicates no edge. This matrix provides instant access to determine if vertices are adjacent.


Advantages:


Constant time to determine adjacency between vertices.
- Useful for dense graphs (graphs with many edges).


Disadvantages:


Inefficient memory usage for sparse graphs.
- Slower for operations like finding incident edges.


In summary, the edge list is simple but inefficient, the adjacency list strikes a balance between efficiency and simplicity, and the adjacency matrix is efficient for certain operations but less memory-friendly. Depending on the application and the characteristics of the graph, one representation may be more suitable than the others.

Data Structure of Graph


A graph data structure represents a collection of vertices and edges, where vertices denote entities and edges represent relationships between them. It allows for the representation and manipulation of complex networks, facilitating tasks such as pathfinding, network analysis, and modeling relationships between data points.


Adjacency List


A clever way to store connections in a graph. Each node holds a list of its neighboring nodes, making it easy to track relationships efficiently. It's like having a social network where each profile knows who its friends are, simplifying navigation through interconnected data. Efficient and intuitive!